home *** CD-ROM | disk | FTP | other *** search
- /*
- devlib: floating point string conversions and es routines.
-
- This file contains all calls to sprintf with floating arguments in DevLib.
-
- Do not use Sherlock in this file.
-
- source: LIBfloat.c
- started: November 7, 1995.
- version: November 7, 1995.
- */
-
-
- #include <LIBlib.h>
- #include <LIBes.h>
-
- #include <stdio.h> /* For sprintf. */
- #include <string.h> /* For strlen */
-
- /*
- Sprintf is just about required for this routine.
- Also, returns 0 unless the floating library is linked in.
- */
- char *
- cvt_double(char * buffer, int buf_size, double d)
- {
-
- #if 1 /* correct code. */
-
- int n = sprintf(buffer, "%f", d);
-
- #else /* Use jump table to call Think C to avoid bugs in CC2. */
-
- extern int _THINK_cvt_double(char * buffer, int buf_size, double d);
- int n = _THINK_cvt_double(buffer, buf_size, d);
-
- #endif
-
- #if 0 /* old kludges. */
-
- /*
- applec or TUPLE_C will be defined when compiling CC2 using CC2.
- _lib_cvt_double converts from CC2 to MPW calling conventions for floats.
- (CC2 passes a *pointer* to all floats: MPW passes the float itself.)
-
- Warning: for this kludge to work, *all* calls to sprintf with floating
- arguments must be converted to calls to cvt_double.
-
- The actual conversion takes place as follows:
- In *this* file the prototype of _lib_cvt_double is
-
- int _lib_cvt_double(char *buffer, double d);
-
- When CC2 compiles the call to _lib_cvt_double it will pass a *pointer* to d.
- Therefore, the prototype for _lib_cvt_double in runlib.c must be
-
- int _lib_cvt_double(char *buffer, double *d);
-
- since runlib.c is compiled with MPW C, not CC2.
- */
-
- // Warning: Must have %f to format floating constants properly for MPW assembler!
-
- #if defined(THINK_C) || defined(TUPLE_C)
-
- // Kludge: with 8-byte doubles, the library may not match.
- n = sprintf(buffer, "%Lg", (long double) d);
-
- #elif defined(applec)
-
- extern int _lib_cvt_double(char *buffer, double d);
- n = _lib_cvt_double(buffer, d);
-
- #else
-
- #error cvt not defined
-
- #endif
-
- #endif /* Old Kludges. */
-
- PERM_ASSERT(n < buf_size);
- return buffer;
- }
-
- void
- edouble(double d)
- {
- epaddouble(d, 0);
- }
-
- /*
- Output a double justified in a field of the given length.
- The floating library must be linked for this to work.
-
- Bug fix 1/12/95: some floats can have *very* long defining strings.
- */
- void
- epaddouble(double d, int field_length)
- {
- char buf [400];
- size_t n;
-
- /* 7/15/93: replace all calls to sprintf with a floating arg by cvt_double. */
- cvt_double(buf, 400, d);
- n = strlen(buf);
- ejustify(buf, n, field_length);
- }
-